# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:merge_docx2_0.py
@Time:2024/8/28 10:37

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""

import os
from docx import Document

def merge_word_files(folder_path, output_filename):
    merged_doc = Document()
    file_list = [f for f in os.listdir(folder_path) if f.endswith('.docx')]
    for filename in file_list:
        file_path = os.path.join(folder_path, filename)
        doc = Document(file_path)
        for element in doc.element.body:
            merged_doc.element.body.append(element)
    merged_doc.save(output_filename)

folder_path = '全国统计公报/'
output_filename = 'merged2_0.docx'
merge_word_files(folder_path, output_filename)